package com.chaoyong.higo.base;

import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

import android.view.View.OnClickListener;
import android.widget.Toast;

import com.chaoyong.higo.R;
import com.chaoyong.higo.utils.AtyManager;

public abstract class BaseActivity extends FragmentActivity implements OnClickListener {
	
	private Dialog mProgressDialog;
    private Toast mToast;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		AtyManager.getAtyManager().addActivity(this);
		
		setContentView(layoutResID());
		findView();
		init();
	}

	/**
	 * layout绑定
	 */
	public abstract int layoutResID();

	/**
	 * 控件绑定
	 */
	public abstract void findView();

	/**
	 * 逻辑操作
	 */
	public abstract void init();
	
	public void showToast(String msg) {
        if (null == mToast)
            mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
        mToast.setText(msg);
        mToast.show();
    }
	
	/**
     * ��ʾtoast
     */
    public void showToast(int msg) {
        showToast(getString(msg));
    }
    
    public void showLoadingView(boolean flag) {
        mProgressDialog = new Dialog(BaseActivity.this,
                R.style.theme_dialog_alert);
        mProgressDialog.setContentView(R.layout.window_layout);
        mProgressDialog.setCancelable(flag);
        mProgressDialog.show();
    }

    public void hideLoadingView() {
        mProgressDialog.dismiss();
    }
}
